<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <audio controls="controls" hidden="hidden" autoplay="autoplay">
        <source src="/music/trip.mp3" type="audio/mpeg" />
    </audio>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function(){
            //获取攻略推荐的数据
            $.get(baseUrl+'/travelCommends',{type:2,pageSize:1},function (data) {
                $(".commend").renderValues(data.list[0],{
                    getHref:getHref
                });
            })

            //获取所有状态为推荐的大攻略
            $.get(baseUrl+'/strategies',{state:1},function (data) {
                $(".strategyCommend").renderValues({list:data},{
                    getHref:getHref
                });
            })

            var regionId;//地区id

            //获取所有状态为推荐的地区
            $.get(baseUrl+"/regions",{state:1},function (data) {
                var temp = '';
                var content ='';
                $.each(data,function (index,ele) {
                    temp += '<li class="nav-item" data-id="'+ele.id+'"><a class="nav-link" data-toggle="pill" href="#pills-'+ele.id+'">'+ele.name+'</a></li>';
                    content += '<div class="tab-pane fade" id="pills-'+ele.id+'">'+ele.id+'</div>';
                })
                $("#pills-tab").append(temp);//标题
                $("#pills-tabContent").append(content);//内容

                //绑定地区的点击事件
                $(".nav-item[data-id]").click(function () {
                    //清空分页条件
                    currentPage = 2;//默认第一页
                    pages=2; //总页数

                    //获取当前点击的地区的id
                    regionId = $(this).data('id');
                    //获取后台生成的html的内容
                    $.get(baseUrl+'/regions/'+regionId+'/strategies',function (data) {
                        $("#pills-"+regionId).html(data);
                    },'html')

                })
            })


            var currentPage = 2;//默认第一页
            var pages=2; //总页数
            var loading = false;//标记是否查询中
            function query() {//分页查询
                if(loading){//代表正在查询,就直接结束方法
                    return;
                }
                loading = true;//标记正在查询中;
                $.get(baseUrl +"/regions/"+regionId+"/strategies", {currentPage: currentPage}, function (data) {
                    $.each(data.list,function (index,ele) {
                        var div = $("#template .mb").clone(true);
                        $(div).find("img").attr('src',ele.coverUrl);
                        $(div).find("span").html(ele.title);
                        $(".classify").append(div);
                    })

                    currentPage++;//当前页数+1
                    pages = data.pages;//设置总页数
                    loading = false;//标记查询结束
                })
            }
            //监听窗口的滚动事件
            $(window).scroll(function () {
                console.log("窗口滚动中...")
                if($(document).scrollTop()+$(window).height()>=$(document).height()){//滚动到底部
                    //如果已经查询到最后一页,就不再查
                    if(currentPage<=pages&&regionId) {
                        query();
                        console.log("分页查询...")
                    }else{
                        $(document).dialog({
                            type : 'notice',
                            content: '<span class="info-text">已经到底了!</span>',
                            autoClose: 1500
                        });
                    }
                }
            })

            //给查询按钮绑定事件
            $("#searchBtn").click(function () {
                var keyword = $("#search").val();
                if(keyword!=null&keyword!=""){
                    window.location.href="/searchPage.html?keyword="+keyword+"&type=1";
                }else{
                    $(document).dialog({
                        titleText: '温馨提示',
                        content: '搜索内容不能为空!',
                    });
                }
            });


        })
    </script>
</head>

<body>
<div id="template" style="display: none">
    <div class="col-6 mb">
        <a href="../strategyCatalogs.html?id=">
            <img class="float-left" >
            <div class="classify-text">
                <span></span>
                <p>0人收藏</p>
            </div>
        </a>
    </div>
</div>

<div class="search-head">
    <div class="row nav-search">
        <div class="col-1">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-9">
            <div class="input-group-sm search">
                <input id="search" class="form-control" placeholder="找攻略">
            </div>
        </div>
        <div class="col-1">
            <i class="fa fa-search" id="searchBtn"
               style="color:white;font-size:25px;position: absolute;top: 23%;left: 0%">
            </i>
        </div>

    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" data-toggle="pill" href="#pills-top">
            <span style="font-weight: bold;">推荐</span>
        </a>
    </li>
</ul>

<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">
        <div class="container commend">
            <a render-key="travelId" render-fun="getHref" data-url="/travelContent.html?id=" >
                <img render-src="coverUrl">
                <p render-html="title"></p>
            </a>
        </div>
        <hr>
        <div class="container strategyCommend">
            <h6>当季推荐</h6>
            <div class="row hot" render-loop="list">
                <div class="col-4">
                    <a href="strategyCatalogs.html">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>



</div>


</body>

</html>